//
//  HYSC.m
//  HYHoney
//
//  Created by dllo on 16/1/19.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "HYSC.h"
#import "RESideMenu.h"
#import "HYZXCell.h"
#import "ModelForZX.h"
#import "UIImageView+WebCache.h"
#import "NetworkHandeler.h"
#import "PushZX.h"
#import "CellForImg.h"
#import "DKNightVersion.h"

@interface HYSC ()<UITableViewDelegate, UITableViewDataSource, NetworkHandelerDelegate>

@property (nonatomic, retain)UITableView *tableV;
@property (nonatomic, retain)NSMutableArray *arr;


@end

@implementation HYSC


- (void)dealloc{

    [_arr release];
    [_tableV release];
    [super dealloc];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"装修指南";
    
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:1 green:1 blue:1 alpha:1], NSForegroundColorAttributeName, nil]];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"xial.png"] style:UIBarButtonItemStylePlain target:self action:@selector(presentLeftMenuViewController:)];
    
    [self createTableView];
    [self HandelData];
}



- (void)createTableView{

    self.tableV = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    
    [self.view addSubview:self.tableV];
    
    [self.tableV registerClass:[HYZXCell class] forCellReuseIdentifier:@"pool"];
    self.tableV.delegate = self;
    self.tableV.dataSource = self;
    self.tableV.dk_backgroundColorPicker =  DKColorWithRGB(0xFFFAFA, 0x27408B);
    
    self.tableV.showsVerticalScrollIndicator = NO;
}



- (void)HandelData{

    NSString *str = @"http://tw.video.luckyamy.com/api/v1.php?cat=pic&page=1&ap=jiaju126&ver=1.0";
    
    [NetworkHandeler handelerJSONWithURL:str delegate:self];
}



- (void)handelerDidComplete:(id)result{

    self.arr = [NSMutableArray array];
    
    for (NSDictionary *dic in result) {
        
        ModelForZX *modelZX = [[ModelForZX alloc] init];
        
        modelZX.title = [dic objectForKey:@"title"];
        modelZX.created_at = [dic objectForKey:@"created_at"];
        modelZX.thumbnail = [dic objectForKey:@"thumbnail"];
        modelZX.screen_name = [dic objectForKey:@"screen_name"];
        
        modelZX.height = [dic objectForKey:@"height"];
        modelZX.width = [dic objectForKey:@"width"];
        
        [self.arr addObject:modelZX];
    }
    [self.tableV reloadData];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    PushZX *push = [[PushZX alloc] init];
    
    ModelForZX *model = [self.arr objectAtIndex:indexPath.row];

    push.model = model;
    
    [self.navigationController pushViewController:push animated:NO];
//    [self.tableV deselectRowAtIndexPath:indexPath animated:NO];
}


- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.arr.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HYZXCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool"];
    ModelForZX *modelZX = [self.arr objectAtIndex:indexPath.row];
    
    [cell passmodel:modelZX];
    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
 
    return [HYZXCell heightForCellZX:self.arr[indexPath.row]];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
